package com.micro.service.auth.server.login.validateCode;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author lvxiucai
 * @description
 * @date 2019/7/20
 */
@Data
@AllArgsConstructor
public class ImageCode implements Serializable{

    /**
     * 图片
     */
    private BufferedImage image;

    /**
     * 随机数
     */
    private String code;

    /**
     * 验证吗有效期（到期的时间点）
     */
    private LocalDateTime expireTime;

    public ImageCode(BufferedImage image,String code,int expireIn){
        this.image = image;
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);//当前时间加上过期时间
    }

    public boolean isExpired() {
        return LocalDateTime.now().isAfter(expireTime);
    }
}
